//
//
//
#include "portocolsingelgift.h"
#include <utf.h>

_LIT8(KInterfaceNo, "interfaceno");

_LIT8(KReqSingelGiftURL, "http://58.246.187.214/client.php?ac=getsingelgift");
_LIT(KReqSingelGiftData, "uid=%s&rand=%s");
_LIT(KReqInfoNone, "\"\"");

CRocketRequestSingelGift::CRocketRequestSingelGift(MNetworkEventObervser* aObserver) : CRocketRequest(aObserver)
	{
		iUrl.Copy(KReqSingelGiftURL());
		iNumber = CMSGSINGELGIFT;
	}

CRocketRequestSingelGift::~CRocketRequestSingelGift()
	{
		
	}

void CRocketRequestSingelGift::SetInfo(const TDesC8& aUid, const TDesC8& aRand)
{
	iUid.Zero();
	iRand.Zero();
	
	iUid.Copy(aUid);
	iRand.Copy(aRand);
}

TBool CRocketRequestSingelGift::Encode()
{
	TBuf<512> buf;
	buf.Format(KReqSingelGiftData(),
				iUid.PtrZ(),
				iRand.PtrZ());
	
	TBuf8<1024> buf8;
	CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8,buf);
	this->iData = buf8.Alloc();
	return ETrue;
}

CRocketResponseSingelGift::CRocketResponseSingelGift()
	{
	
	}

CRocketResponseSingelGift::~CRocketResponseSingelGift()
	{
	
	}

void CRocketResponseSingelGift::OnEndElementL(const Xml::RTagInfo &aElement, 
										TInt aErrorCode)
{
	
}

// XML tags
//?????
_LIT8(KSingelGiftTag, "getsingelgift");
_LIT8(KRetTag, "ret");

void CRocketResponseSingelGift::OnStartElementL(const Xml::RTagInfo& aElement,
						const Xml::RAttributeArray& aAttributes,
						TInt aErrorCode)
{
	if(aElement.LocalName().DesC() == KInterfaceNo)
	{
		
	}
	else if(aElement.LocalName().DesC() == KSingelGiftTag)
	{
		for(TInt nIndex = 0; nIndex < aAttributes.Count(); nIndex ++)
		{
			//Xml::RAttribute attr = aAttributes.At(nIndex);
			if(0 == aAttributes[nIndex].Attribute().LocalName().DesC().Compare(KRetTag))
			{
				TLex8 aLex(aAttributes[nIndex].Value().DesC());
				aLex.Val(iReturnNumber);
			}
		}
	}
}
